/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nite.gestures;

import com.primesense.NITE.IdValueEventArgs;
import com.primesense.NITE.SteadyDetector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.OpenNI.GeneralException;
import org.OpenNI.IObservable;
import org.OpenNI.IObserver;

/**
 *
 * @author xvanek9
 */
public class SteadyGesture extends AbstractGesture {
    
        PrimaryPointUpdateObserver obs;

    public PrimaryPointUpdateObserver getObs() {
        return obs;
    }

    public void setObs(PrimaryPointUpdateObserver obs) {
        this.obs = obs;
    }
    
    public SteadyDetector init(int duration){
        SteadyDetector sd = null;
        try {
            sd = new SteadyDetector();
            sd.setDetectionDuration(5000);
            sd.setMaxDeviationForSteady(20);
            sd.getNotSteadyEvent().addObserver(new NotSteadyObserver());
            sd.getSteadyEvent().addObserver(new SteadyObserver());
            obs = new PrimaryPointUpdateObserver();
            sd.getPrimaryPointUpdateEvent().addObserver(obs);
        } catch (GeneralException ex) {
            Logger.getLogger(SteadyGesture.class.getName()).log(Level.SEVERE, null, ex);
        }
        return sd;
    }
    
    private class NotSteadyObserver implements IObserver <IdValueEventArgs>{

        @Override
        public void update(IObservable<IdValueEventArgs> io, IdValueEventArgs args) {
            //System.out.println("Hand " + args.getId() + " not steady.");
        }
    }
    
    private class SteadyObserver implements IObserver <IdValueEventArgs>{

        @Override
        public void update(IObservable<IdValueEventArgs> io, IdValueEventArgs args) {
//            System.out.println("Hand " + args.getId() + " steady." + args.getValue());
        }
    }    
}
